package com.salmon.oss.config;

import com.salmon.oss.properties.AdminProperties;
import org.iq80.leveldb.DB;
import org.iq80.leveldb.DBFactory;
import org.iq80.leveldb.Options;
import org.iq80.leveldb.impl.Iq80DBFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;

@Configuration
@EnableConfigurationProperties({AdminProperties.class})
public class LevelDBConfig {

    @Resource
    private AdminProperties adminProperties;

    @Bean("levelDB")
    public DB levelDB() throws IOException {
        DBFactory factory = new Iq80DBFactory();
        Options options = new Options();
        options.createIfMissing(true);
        return factory.open(new File(this.adminProperties.getLeveldb_directory()), options);
    }
}
